package com.wdg.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author : wdg；
 * @Date : 2025/3/30 20:00；
 * @Version : v1.0.0；
 * @Description: 类描述信息；
 **/
public class SessionInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession();
        String username = (String) session.getAttribute("username");
        if(username==null){
            request.setAttribute("err","你没有权限，请登录后再访问！");
            request.getRequestDispatcher("login.jsp").forward(request,response);
            return false;
        }else {
            return true;
        }
    }
}
